package com.db.httpserver;


import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import java.util.concurrent.atomic.AtomicInteger;

public class Foo {
    private static String url = "http://127.0.0.1:4444/";
    private static AtomicInteger fails = new AtomicInteger(0);

    public static void main(String[] args) {
        try {
            HttpClient client = new DefaultHttpClient();
            long time = 0l;
            for (int i = 0; i < 10000; i++) {
                time -= System.currentTimeMillis();
                HttpGet method = new HttpGet(url);

                HttpResponse response = client.execute(method);
                response.getEntity().consumeContent();
                if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode())
                    fails.incrementAndGet();
                time += System.currentTimeMillis();
            }
            System.out.println("time = " + time + " fails = " + fails);

        } catch (Exception e) {
            fails.incrementAndGet();
            e.printStackTrace();
        }

    }
}
